<template>
    <div>
        <el-form style="width: 300px;" ref="form" :model="form" label-width="80px">
            <el-form-item label="仓库名称">
                <el-select v-model="form.whId" placeholder="请选择仓库" @change="this.changeWarehouse">
                    <el-option v-for="(item, index) in warehouseList" :label="item.whName" :value="item.whId"></el-option>
                </el-select>
            </el-form-item>
        </el-form>
        <div ref="main" style="width: 100%;height: 80vh;"></div>
    </div>
</template>
<sty>


</sty>
<script>

import axios from 'axios';
import * as echarts from 'echarts'

export default {
    mounted() {
        //下拉菜单数据：仓库名称
        axios.get("http://192.168.124.96:9090/getUseWarehouse").then(res => {
            this.warehouseList = res.data.data;
            this.form.whId=this.warehouseList[0].whId
            //console.log(this.warehouseList);
            this.initData();
        })

        // 基于准备好的dom，初始化echarts实例
        // var myChart = echarts.init(document.getElementById('main'));//如果节点使用id定义
        //this.initData();
    },
    data() {
        return {
            form: {
                whId: '',
            },
            warehouseList: []
        }
    },
    methods: {
        changeWarehouse(){
            this.initData();
        },

        initData() {
            axios.get("http://192.168.124.96:9090/getPieData/" + this.form.whId).then(res => {
                if (res.data.code != 0) {
                    this.$message({
                        type: "error",
                        message: res.data.msg
                    })
                    this.$router.replace("/")
                    return;
                }
                var myChart = echarts.init(this.$refs.main);//如果节点使用ref定义
                // 绘制图表
                myChart.setOption({
                    title: {
                        text: '库区容量分布',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    left: 'center',
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: 'Access From',
                            type: 'pie',
                            radius: '50%',
                            data: res.data.data,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                });
            })


        }
    }
}
</script>